home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Demos
/
A.D. Software
/
OOFILE
/
Buildable, limited OOFILE
/
samples
/
ooftst01.cpp
next >
Wrap
C/C++ Source or Header
|
1996-03-17
|
4KB
|
110 lines
// Copyright 1994 A.D. Software. All Rights Reserved
// OOFTEST1
// This sample tests the database backend by creating a single table
// and storing and retrieving indexed data.
// Simple stream I/O is used to interact with the user.
// NOTE the odd sizes in the fields below are to help trap alignment issues
#include "oofile.hpp"
#include "ooftst01.inc"
int main()
{
cout << "OOFILE Validation Suite - Test 1\n"
<< "Simple test to store some data and retrieve it\n"
<< "in a single-table database, with no relations\n";
dbConnect_ctree theDB;
dbPeople People;
theDB.useSeparateFiles(); // note the blank connection names!
// this test creates People.dat, People.idx & Blobs
#ifdef _Macintosh
// this feature only on the Mac at present
#define kExistsName ":test01:People.dat"
#define kDatabaseName "test01"
#else
#define kExistsName "People.dat"
#define kDatabaseName ""
#endif
if (dbConnect::fileExists(kExistsName)) {
theDB.openConnection(kDatabaseName);
People.deleteAll();
}
else {
theDB.newConnection(kDatabaseName);
}
People.AddTestData();
People.setSortOrder(People.LastName);
cout << "Listing records\n" << People;
// NOTE we dumped all the fields of People this time, from now on we will
// use dbViews to restrict the fields listed
dbView justNames(People);
justNames << People.LastName << People.OtherNames;
People.setSortOrder(People.OtherNames);
cout << "Listing records in OtherNames order\n" << justNames << endl;
cout << "Now retrieving by index\n";
cout << "Retrieving Taylor: " << People[People.LastName=="Taylor"].LastName << endl;
cout << "Retrieving Smith by Salary: ";
People[People.Salary==0];
cout << People.LastName << endl << endl;
People.search(People.LastName=="Dent");
cout << "Listing two Dent records: " << endl << justNames << endl;
cout << endl << "now producing a subset of Taylor & Dent" << endl;
dbPeople entrepeneurs = People;
entrepeneurs.search(entrepeneurs.LastName=="Taylor");
entrepeneurs += People;
cout << (dbView(entrepeneurs) << entrepeneurs.LastName << entrepeneurs.OtherNames) << endl;
dbPeople savedEnts = entrepeneurs;
cout << "Just cloned a selection of " << savedEnts.count() << " records" << endl;
cout << endl << "now reducing original via Intersection to Dent" << endl;
entrepeneurs &= People; // Dent, Taylor & Dent
cout << entrepeneurs;
cout << endl << "now Inverting to Smith & Taylor" << endl;
~entrepeneurs;
cout << (dbView(entrepeneurs) << entrepeneurs.LastName << entrepeneurs.OtherNames) << endl;
// Dent inverted
cout << "Show the cloned selection is still Dent & Taylor" << endl
<< (dbView(savedEnts) << savedEnts.LastName << savedEnts.OtherNames) << endl;
cout << endl << "now reducing via Difference to Dent" << endl;
savedEnts -= entrepeneurs; // Dent, Taylor - Smith, Taylor
cout << (dbView(savedEnts) << savedEnts.LastName << savedEnts.OtherNames) << endl;
// demonstrate going to a specific relative record in a selection
// then going to the previous record, as would be common in a GUI
// by double-clicking a line in a browser, then pressing Prev Record
People.selectAll();
People.setSortOrder(People.LastName);
cout << "Retrieving Taylor by relative record number: ";
People.gotoRecord(3);
cout << People.LastName << endl << endl;
cout << "Retrieving previous record Smith: ";
People.prev();
cout << People.LastName << endl << endl;
cout << "Now finding people who've been paid in the last 2 weeks " << endl;
People.search(People.LastPaid > dbDate::currentDate()-14);
cout << (dbView(People) << People.LastName << People.OtherNames << People.LastPaid) << endl;
cout << "Test Completed" << endl;
return EXIT_SUCCESS;
}